From a5980a4e95a125e96606c4b75b857034c92d6b81 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Fri, 18 Feb 2022 11:04:01 -0700 Subject: [PATCH] use precompiled headers to speed up compile time (#851) * speed up compiles with precompiled headers. * workaround QTBUG with precompiled headers and clang. * avoid including QtCore. * add ability to turn off precompiled headers. --- .gitignore | 1 + CMakeLists.txt | 23 +++++++++++++++++++++++ GPSBabel.pro | 9 +++++++++ mynav.cc | 2 +- precompiled_headers.h | 41 +++++++++++++++++++++++++++++++++++++++++ src/core/codecdevice.cc | 2 +- src/core/codecdevice.h | 3 ++- src/core/textstream.cc | 2 +- 8 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 precompiled_headers.h diff --git a/.gitignore b/.gitignore index 957c3cac4..096b82de5 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ CMakeFiles/ *.swp /tmp/ /mkcapabilities +/gpsbabel.gch/ /gpsbabel.rc /autogen/ /makedoc diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dcb4d4a9..d0acd5774 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,29 @@ if(${QT_VERSION_MAJOR} EQUAL "6") list(APPEND QT_LIBRARIES Qt${QT_VERSION_MAJOR}::Core5Compat) endif() +option(GPSBABEL_ENABLE_PCH "enable precompiled headers." ON) +if (GPSBABEL_ENABLE_PCH) + target_precompile_headers(gpsbabel PRIVATE + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + "$<$:>" + ) +endif() + # RESOURCES set(RESOURCES gpsbabel.qrc) diff --git a/GPSBabel.pro b/GPSBabel.pro index 49faaaf01..47b2be048 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -26,6 +26,15 @@ CONFIG += console CONFIG -= app_bundle CONFIG += c++17 CONFIG += link_pkgconfig +!disable_pch { + # avoid QTBUG-72404, QTBUG-79694 which were fixed in 5.14.0 + versionAtLeast(QT_VERSION, 5.14.0) | !contains(QMAKE_CXX, .*clang.*) { + CONFIG += precompile_header + PRECOMPILED_HEADER = precompiled_headers.h + } else { + message("Not using precompiled headers due to QTBUG.") + } +} TEMPLATE = app diff --git a/mynav.cc b/mynav.cc index f2fbf982e..5fbe9b902 100644 --- a/mynav.cc +++ b/mynav.cc @@ -30,7 +30,7 @@ #include #include -#include +#include "src/core/textstream.h" #include "mynav.h" diff --git a/precompiled_headers.h b/precompiled_headers.h new file mode 100644 index 000000000..47705c843 --- /dev/null +++ b/precompiled_headers.h @@ -0,0 +1,41 @@ +/* + Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +// This list is from defs.h. Adding other commonly used headers doesn't help. + +#if defined __cplusplus +#include // for sort, stable_sort +#include // for M_PI +#include // for va_list +#include // for NULL, nullptr_t, size_t +#include // for int32_t, uint32_t +#include // for NULL, fprintf, FILE, stdout +#include // for time_t +#include // for optional +#include // for move + +#include // for QDebug +#include // for QList, QList<>::const_reverse_iterator, QList<>::reverse_iterator +#include // for QScopedPointer +#include // for QString +#include // for QTextCodec +#include // for QVector +#include // for CaseInsensitive +#include // for foreach +#endif diff --git a/src/core/codecdevice.cc b/src/core/codecdevice.cc index 13290d014..77e322e45 100644 --- a/src/core/codecdevice.cc +++ b/src/core/codecdevice.cc @@ -17,12 +17,12 @@ */ +#include // for assert #include // for memcpy #include // for min #include // for QByteArray #include // for QChar -#include // for QFile #include // for QFlags #include "defs.h" // for list_codecs, warning diff --git a/src/core/codecdevice.h b/src/core/codecdevice.h index 320d9aa90..6ccb7e8ac 100644 --- a/src/core/codecdevice.h +++ b/src/core/codecdevice.h @@ -18,11 +18,12 @@ */ #include // for QIODevice +#include // for QIODeviceBase::OpenMode #include // for QString #include // for QTextCodec #include // for QTextDecoder #include // for QTextEncoder -#include // for qint64, QIODeviceBase::OpenMode +#include // for qint64 #include "src/core/file.h" // for File diff --git a/src/core/textstream.cc b/src/core/textstream.cc index 49c10ba88..2b6f1140e 100644 --- a/src/core/textstream.cc +++ b/src/core/textstream.cc @@ -18,7 +18,7 @@ */ -#include // for qint64, QT_VERSION, QT_VERSION_CHECK +#include // for qint64, QT_VERSION, QT_VERSION_CHECK #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #include // for QByteArrayView -- 2.30.2